package edu.mit.media.fv.blocks
{
	import edu.mit.media.fv.components.*;
	import edu.mit.media.fv.events.*;
	import edu.mit.media.fv.fluidspace.*;
	import edu.mit.media.fv.icons.AQUserIcon;
	
	public class UserModel extends Model
	{
		private static var ALL_MODELS:Array = new Array();
		public static function getUserModels():Array{
			return ALL_MODELS;
		}
		private var activeBlockInstance:Block = null;
		private var groupBlockInstances:Block = null;
		public function UserModel(id:int, controller:FluidSpace, name:String)
		{
			// last parameter is true indicating that there's audio
			super(id, controller, name, true);
			this.tivoCapable = true;
			ALL_MODELS.push(this);
		}
		public override function getBlockInstance():Block{
			return new CircleBlock(this, this.controller, new AQUserIcon(), this.name, 0xB0F284);
		}
		public override function getActiveInstance():Block{
			if(this.activeBlockInstance == null){
				this.activeBlockInstance =  this.getBlockInstance();
			}
			this.activeBlockInstance.x = 0;
			this.activeBlockInstance.y = 0;
			return this.activeBlockInstance;
		}
		public override function getGroupInstance():Block{
			this.groupBlockInstances =this.getBlockInstance();
			this.groupBlockInstances.x = Math.random()*650;
			this.groupBlockInstances.y = Math.random()*400;
			return this.groupBlockInstances;
		}
		public override function openModel():void{
			var data:Object = new Object();
			data.command = FluidConstants.REQUEST_OPEN_OBJECT;
			data.id = this.id;
			data.type = FluidConstants.USER;
			var event:FVNetworkEvent = new FVNetworkEvent(data);
			FluidEventHandler.dispatchEvent(event);
		}
		public override function onAudioEdit(volume:Number, balance:Number):void{
			var data:Object = new Object();
			data.command = FluidConstants.REQUEST_EDIT_OBJECT;
			data.id = this.id;
			data.volume = volume;
			data.pan = balance;
			data.type = FluidConstants.USER;
			var event:FVNetworkEvent = new FVNetworkEvent(data);
			FluidEventHandler.dispatchEvent(event);
		}

	}
}